<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg8.php" ?>
<?php include_once "ewmysql8.php" ?>
<?php include_once "phpfn8.php" ?>
<?php include_once "transactioninfo.php" ?>
<?php include_once "userinfo.php" ?>
<?php include_once "addressinfo.php" ?>
<?php include_once "purchaseproductinfo.php" ?>
<?php include_once "transaction_loginfo.php" ?>
<?php include_once "purchaseproductgridcls.php" ?>
<?php include_once "transaction_loggridcls.php" ?>
<?php include_once "addressgridcls.php" ?>
<?php include_once "userfn8.php" ?>
<?php ew_Header(TRUE) ?>
<?php

// Create page object
$transaction_edit = new ctransaction_edit();
$Page =& $transaction_edit;

// Page init
$transaction_edit->Page_Init();

// Page main
$transaction_edit->Page_Main();
?>
<?php include_once "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var transaction_edit = new ew_Page("transaction_edit");

// page properties
transaction_edit.PageID = "edit"; // page ID
transaction_edit.FormID = "ftransactionedit"; // form ID
var EW_PAGE_ID = transaction_edit.PageID; // for backward compatibility

// extend page with ValidateForm function
transaction_edit.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = 1;
	for (i=0; i<rowcnt; i++) {
		infix = "";
		elm = fobj.elements["x" + infix + "_status_transaction"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($transaction->status_transaction->FldCaption()) ?>");

		// Set up row object
		var row = {};
		row["index"] = infix;
		for (var j = 0; j < fobj.elements.length; j++) {
			var el = fobj.elements[j];
			var len = infix.length + 2;
			if (el.name.substr(0, len) == "x" + infix + "_") {
				var elname = "x_" + el.name.substr(len);
				if (ewLang.isObject(row[elname])) { // already exists
					if (ewLang.isArray(row[elname])) {
						row[elname][row[elname].length] = el; // add to array
					} else {
						row[elname] = [row[elname], el]; // convert to array
					}
				} else {
					row[elname] = el;
				}
			}
		}
		fobj.row = row;

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}

	// Process detail page
	var detailpage = (fobj.detailpage) ? fobj.detailpage.value : "";
	if (detailpage != "") {
		return eval(detailpage+".ValidateForm(fobj)");
	}
	return true;
}

// extend page with Form_CustomValidate function
transaction_edit.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
transaction_edit.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
transaction_edit.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
//-->

</script>
<p class="phpmaker ewTitle"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $transaction->TableCaption() ?></p>
<p class="phpmaker"><a href="<?php echo $transaction->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></p>
<?php $transaction_edit->ShowPageHeader(); ?>
<?php
$transaction_edit->ShowMessage();
?>
<form name="ftransactionedit" id="ftransactionedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return transaction_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="transaction">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($transaction->order_no->Visible) { // order_no ?>
	<tr id="r_order_no"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->order_no->FldCaption() ?></td>
		<td<?php echo $transaction->order_no->CellAttributes() ?>><span id="el_order_no">
<div<?php echo $transaction->order_no->ViewAttributes() ?>><?php echo $transaction->order_no->EditValue ?></div>
<input type="hidden" name="x_order_no" id="x_order_no" value="<?php echo ew_HtmlEncode($transaction->order_no->CurrentValue) ?>">
</span><?php echo $transaction->order_no->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->user_id->Visible) { // user_id ?>
	<tr id="r_user_id"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->user_id->FldCaption() ?></td>
		<td<?php echo $transaction->user_id->CellAttributes() ?>><span id="el_user_id">
<div<?php echo $transaction->user_id->ViewAttributes() ?>><?php echo $transaction->user_id->EditValue ?></div>
<input type="hidden" name="x_user_id" id="x_user_id" value="<?php echo ew_HtmlEncode($transaction->user_id->CurrentValue) ?>">
</span><?php echo $transaction->user_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->amount->Visible) { // amount ?>
	<tr id="r_amount"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->amount->FldCaption() ?></td>
		<td<?php echo $transaction->amount->CellAttributes() ?>><span id="el_amount">
<div<?php echo $transaction->amount->ViewAttributes() ?>><?php echo $transaction->amount->EditValue ?></div>
<input type="hidden" name="x_amount" id="x_amount" value="<?php echo ew_HtmlEncode($transaction->amount->CurrentValue) ?>">
</span><?php echo $transaction->amount->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->status_payment->Visible) { // status_payment ?>
	<tr id="r_status_payment"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->status_payment->FldCaption() ?></td>
		<td<?php echo $transaction->status_payment->CellAttributes() ?>><span id="el_status_payment">
<div<?php echo $transaction->status_payment->ViewAttributes() ?>><?php echo $transaction->status_payment->EditValue ?></div>
<input type="hidden" name="x_status_payment" id="x_status_payment" value="<?php echo ew_HtmlEncode($transaction->status_payment->CurrentValue) ?>">
</span><?php echo $transaction->status_payment->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->status_transaction->Visible) { // status_transaction ?>
	<tr id="r_status_transaction"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->status_transaction->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $transaction->status_transaction->CellAttributes() ?>><span id="el_status_transaction">
<div id="tp_x_status_transaction" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME ?>"><label><input type="radio" name="x_status_transaction" id="x_status_transaction" value="{value}"<?php echo $transaction->status_transaction->EditAttributes() ?>></label></div>
<div id="dsl_x_status_transaction" data-repeatcolumn="5" class="ewItemList">
<?php
$arwrk = $transaction->status_transaction->EditValue;
if (is_array($arwrk)) {
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($transaction->status_transaction->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " checked=\"checked\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="radio" name="x_status_transaction" id="x_status_transaction" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $transaction->status_transaction->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span><?php echo $transaction->status_transaction->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->total_item->Visible) { // total_item ?>
	<tr id="r_total_item"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->total_item->FldCaption() ?></td>
		<td<?php echo $transaction->total_item->CellAttributes() ?>><span id="el_total_item">
<div<?php echo $transaction->total_item->ViewAttributes() ?>><?php echo $transaction->total_item->EditValue ?></div>
<input type="hidden" name="x_total_item" id="x_total_item" value="<?php echo ew_HtmlEncode($transaction->total_item->CurrentValue) ?>">
</span><?php echo $transaction->total_item->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->total_weight->Visible) { // total_weight ?>
	<tr id="r_total_weight"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->total_weight->FldCaption() ?></td>
		<td<?php echo $transaction->total_weight->CellAttributes() ?>><span id="el_total_weight">
<div<?php echo $transaction->total_weight->ViewAttributes() ?>><?php echo $transaction->total_weight->EditValue ?></div>
<input type="hidden" name="x_total_weight" id="x_total_weight" value="<?php echo ew_HtmlEncode($transaction->total_weight->CurrentValue) ?>">
</span><?php echo $transaction->total_weight->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->postage_price->Visible) { // postage_price ?>
	<tr id="r_postage_price"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->postage_price->FldCaption() ?></td>
		<td<?php echo $transaction->postage_price->CellAttributes() ?>><span id="el_postage_price">
<div<?php echo $transaction->postage_price->ViewAttributes() ?>><?php echo $transaction->postage_price->EditValue ?></div>
<input type="hidden" name="x_postage_price" id="x_postage_price" value="<?php echo ew_HtmlEncode($transaction->postage_price->CurrentValue) ?>">
</span><?php echo $transaction->postage_price->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->items_price->Visible) { // items_price ?>
	<tr id="r_items_price"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->items_price->FldCaption() ?></td>
		<td<?php echo $transaction->items_price->CellAttributes() ?>><span id="el_items_price">
<div<?php echo $transaction->items_price->ViewAttributes() ?>><?php echo $transaction->items_price->EditValue ?></div>
<input type="hidden" name="x_items_price" id="x_items_price" value="<?php echo ew_HtmlEncode($transaction->items_price->CurrentValue) ?>">
</span><?php echo $transaction->items_price->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->type_price->Visible) { // type_price ?>
	<tr id="r_type_price"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->type_price->FldCaption() ?></td>
		<td<?php echo $transaction->type_price->CellAttributes() ?>><span id="el_type_price">
<div<?php echo $transaction->type_price->ViewAttributes() ?>><?php echo $transaction->type_price->EditValue ?></div>
<input type="hidden" name="x_type_price" id="x_type_price" value="<?php echo ew_HtmlEncode($transaction->type_price->CurrentValue) ?>">
</span><?php echo $transaction->type_price->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->shipping_address_id->Visible) { // shipping_address_id ?>
	<tr id="r_shipping_address_id"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->shipping_address_id->FldCaption() ?></td>
		<td<?php echo $transaction->shipping_address_id->CellAttributes() ?>><span id="el_shipping_address_id">
<div<?php echo $transaction->shipping_address_id->ViewAttributes() ?>><?php echo $transaction->shipping_address_id->EditValue ?></div>
<input type="hidden" name="x_shipping_address_id" id="x_shipping_address_id" value="<?php echo ew_HtmlEncode($transaction->shipping_address_id->CurrentValue) ?>">
</span><?php echo $transaction->shipping_address_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->paydate->Visible) { // paydate ?>
	<tr id="r_paydate"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->paydate->FldCaption() ?></td>
		<td<?php echo $transaction->paydate->CellAttributes() ?>><span id="el_paydate">
<div<?php echo $transaction->paydate->ViewAttributes() ?>><?php echo $transaction->paydate->EditValue ?></div>
<input type="hidden" name="x_paydate" id="x_paydate" value="<?php echo ew_HtmlEncode($transaction->paydate->CurrentValue) ?>">
</span><?php echo $transaction->paydate->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->isInvalid->Visible) { // isInvalid ?>
	<tr id="r_isInvalid"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->isInvalid->FldCaption() ?></td>
		<td<?php echo $transaction->isInvalid->CellAttributes() ?>><span id="el_isInvalid">
<div<?php echo $transaction->isInvalid->ViewAttributes() ?>><?php echo $transaction->isInvalid->EditValue ?></div>
<input type="hidden" name="x_isInvalid" id="x_isInvalid" value="<?php echo ew_HtmlEncode($transaction->isInvalid->CurrentValue) ?>">
</span><?php echo $transaction->isInvalid->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->remarks->Visible) { // remarks ?>
	<tr id="r_remarks"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->remarks->FldCaption() ?></td>
		<td<?php echo $transaction->remarks->CellAttributes() ?>><span id="el_remarks">
<textarea name="x_remarks" id="x_remarks" cols="70" rows="6"<?php echo $transaction->remarks->EditAttributes() ?>><?php echo $transaction->remarks->EditValue ?></textarea>
</span><?php echo $transaction->remarks->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($transaction->consignment_no->Visible) { // consignment_no ?>
	<tr id="r_consignment_no"<?php echo $transaction->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $transaction->consignment_no->FldCaption() ?></td>
		<td<?php echo $transaction->consignment_no->CellAttributes() ?>><span id="el_consignment_no">
<input type="text" name="x_consignment_no" id="x_consignment_no" size="70" maxlength="255" value="<?php echo $transaction->consignment_no->EditValue ?>"<?php echo $transaction->consignment_no->EditAttributes() ?>>
</span><?php echo $transaction->consignment_no->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($transaction->id->CurrentValue) ?>">
<p>
<?php if ($transaction->getCurrentDetailTable() == "purchaseproduct" && $purchaseproduct->DetailEdit) { ?>
<br>
<?php include_once "purchaseproductgrid.php" ?>
<br>
<?php } ?>
<?php if ($transaction->getCurrentDetailTable() == "transaction_log" && $transaction_log->DetailEdit) { ?>
<br>
<?php include_once "transaction_loggrid.php" ?>
<br>
<?php } ?>
<?php if ($transaction->getCurrentDetailTable() == "address" && $address->DetailEdit) { ?>
<br>
<?php include_once "addressgrid.php" ?>
<br>
<?php } ?>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<?php
$transaction_edit->ShowPageFooter();
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
?>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include_once "footer.php" ?>
<?php
$transaction_edit->Page_Terminate();
?>
<?php

//
// Page class
//
class ctransaction_edit {

	// Page ID
	var $PageID = 'edit';

	// Table name
	var $TableName = 'transaction';

	// Page object name
	var $PageObjName = 'transaction_edit';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $transaction;
		if ($transaction->UseTokenInUrl) $PageUrl .= "t=" . $transaction->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
	}

	function getFailureMessage() {
		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
	}

	function setFailureMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
	}

	function getSuccessMessage() {
		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
	}

	function setSuccessMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage, "");
		if ($sMessage <> "") { // Message in Session, display
			echo "<p class=\"ewMessage\">" . $sMessage . "</p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$sSuccessMessage = $this->getSuccessMessage();
		$this->Message_Showing($sSuccessMessage, "success");
		if ($sSuccessMessage <> "") { // Message in Session, display
			echo "<p class=\"ewSuccessMessage\">" . $sSuccessMessage . "</p>";
			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$sErrorMessage = $this->getFailureMessage();
		$this->Message_Showing($sErrorMessage, "failure");
		if ($sErrorMessage <> "") { // Message in Session, display
			echo "<p class=\"ewErrorMessage\">" . $sErrorMessage . "</p>";
			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
	}
	var $PageHeader;
	var $PageFooter;

	// Show Page Header
	function ShowPageHeader() {
		$sHeader = $this->PageHeader;
		$this->Page_DataRendering($sHeader);
		if ($sHeader <> "") { // Header exists, display
			echo "<p class=\"phpmaker\">" . $sHeader . "</p>";
		}
	}

	// Show Page Footer
	function ShowPageFooter() {
		$sFooter = $this->PageFooter;
		$this->Page_DataRendered($sFooter);
		if ($sFooter <> "") { // Fotoer exists, display
			echo "<p class=\"phpmaker\">" . $sFooter . "</p>";
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $transaction;
		if ($transaction->UseTokenInUrl) {
			if ($objForm)
				return ($transaction->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($transaction->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function ctransaction_edit() {
		global $conn, $Language;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();

		// Table object (transaction)
		if (!isset($GLOBALS["transaction"])) {
			$GLOBALS["transaction"] = new ctransaction();
			$GLOBALS["Table"] =& $GLOBALS["transaction"];
		}

		// Table object (user)
		if (!isset($GLOBALS['user'])) $GLOBALS['user'] = new cuser();

		// Table object (address)
		if (!isset($GLOBALS['address'])) $GLOBALS['address'] = new caddress();

		// Table object (purchaseproduct)
		if (!isset($GLOBALS['purchaseproduct'])) $GLOBALS['purchaseproduct'] = new cpurchaseproduct();

		// Table object (transaction_log)
		if (!isset($GLOBALS['transaction_log'])) $GLOBALS['transaction_log'] = new ctransaction_log();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'edit', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'transaction', TRUE);

		// Start timer
		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

		// Open connection
		if (!isset($conn)) $conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $transaction;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}

		// Create form object
		$objForm = new cFormObj();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();
		$this->Page_Redirecting($url);

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $DbMasterFilter;
	var $DbDetailFilter;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $transaction;

		// Load key from QueryString
		if (@$_GET["id"] <> "")
			$transaction->id->setQueryStringValue($_GET["id"]);

		// Set up master detail parameters
		$this->SetUpMasterParms();
		if (@$_POST["a_edit"] <> "") {
			$transaction->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->LoadFormValues(); // Get form values

			// Set up detail parameters
			$this->SetUpDetailParms();

			// Validate form
			if (!$this->ValidateForm()) {
				$transaction->CurrentAction = ""; // Form error, reset action
				$this->setFailureMessage($gsFormError);
				$transaction->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		} else {
			$transaction->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($transaction->id->CurrentValue == "")
			$this->Page_Terminate("transactionlist.php"); // Invalid key, return to list

		// Set up detail parameters
		$this->SetUpDetailParms();
		switch ($transaction->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					$this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("transactionlist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$transaction->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					$this->setSuccessMessage($Language->Phrase("UpdateSuccess")); // Update success
					if ($transaction->getCurrentDetailTable() <> "") // Master/detail edit
						$sReturnUrl = $transaction->getDetailUrl();
					else
						$sReturnUrl = $transaction->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$transaction->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

		// Render the record
		$transaction->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$transaction->ResetAttrs();
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $transaction;

		// Get upload data
		$index = $objForm->Index; // Save form index
		$objForm->Index = 0;
		$confirmPage = (strval($objForm->GetValue("a_confirm")) <> "");
		$objForm->Index = $index; // Restore form index
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $transaction;
		if (!$transaction->order_no->FldIsDetailKey) {
			$transaction->order_no->setFormValue($objForm->GetValue("x_order_no"));
		}
		if (!$transaction->user_id->FldIsDetailKey) {
			$transaction->user_id->setFormValue($objForm->GetValue("x_user_id"));
		}
		if (!$transaction->amount->FldIsDetailKey) {
			$transaction->amount->setFormValue($objForm->GetValue("x_amount"));
		}
		if (!$transaction->status_payment->FldIsDetailKey) {
			$transaction->status_payment->setFormValue($objForm->GetValue("x_status_payment"));
		}
		if (!$transaction->status_transaction->FldIsDetailKey) {
			$transaction->status_transaction->setFormValue($objForm->GetValue("x_status_transaction"));
		}
		if (!$transaction->total_item->FldIsDetailKey) {
			$transaction->total_item->setFormValue($objForm->GetValue("x_total_item"));
		}
		if (!$transaction->total_weight->FldIsDetailKey) {
			$transaction->total_weight->setFormValue($objForm->GetValue("x_total_weight"));
		}
		if (!$transaction->postage_price->FldIsDetailKey) {
			$transaction->postage_price->setFormValue($objForm->GetValue("x_postage_price"));
		}
		if (!$transaction->items_price->FldIsDetailKey) {
			$transaction->items_price->setFormValue($objForm->GetValue("x_items_price"));
		}
		if (!$transaction->type_price->FldIsDetailKey) {
			$transaction->type_price->setFormValue($objForm->GetValue("x_type_price"));
		}
		if (!$transaction->shipping_address_id->FldIsDetailKey) {
			$transaction->shipping_address_id->setFormValue($objForm->GetValue("x_shipping_address_id"));
		}
		if (!$transaction->paydate->FldIsDetailKey) {
			$transaction->paydate->setFormValue($objForm->GetValue("x_paydate"));
			$transaction->paydate->CurrentValue = ew_UnFormatDateTime($transaction->paydate->CurrentValue, 7);
		}
		if (!$transaction->modified_date->FldIsDetailKey) {
			$transaction->modified_date->setFormValue($objForm->GetValue("x_modified_date"));
			$transaction->modified_date->CurrentValue = ew_UnFormatDateTime($transaction->modified_date->CurrentValue, 11);
		}
		if (!$transaction->isInvalid->FldIsDetailKey) {
			$transaction->isInvalid->setFormValue($objForm->GetValue("x_isInvalid"));
		}
		if (!$transaction->remarks->FldIsDetailKey) {
			$transaction->remarks->setFormValue($objForm->GetValue("x_remarks"));
		}
		if (!$transaction->consignment_no->FldIsDetailKey) {
			$transaction->consignment_no->setFormValue($objForm->GetValue("x_consignment_no"));
		}
		if (!$transaction->id->FldIsDetailKey)
			$transaction->id->setFormValue($objForm->GetValue("x_id"));
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $transaction;
		$this->LoadRow();
		$transaction->id->CurrentValue = $transaction->id->FormValue;
		$transaction->order_no->CurrentValue = $transaction->order_no->FormValue;
		$transaction->user_id->CurrentValue = $transaction->user_id->FormValue;
		$transaction->amount->CurrentValue = $transaction->amount->FormValue;
		$transaction->status_payment->CurrentValue = $transaction->status_payment->FormValue;
		$transaction->status_transaction->CurrentValue = $transaction->status_transaction->FormValue;
		$transaction->total_item->CurrentValue = $transaction->total_item->FormValue;
		$transaction->total_weight->CurrentValue = $transaction->total_weight->FormValue;
		$transaction->postage_price->CurrentValue = $transaction->postage_price->FormValue;
		$transaction->items_price->CurrentValue = $transaction->items_price->FormValue;
		$transaction->type_price->CurrentValue = $transaction->type_price->FormValue;
		$transaction->shipping_address_id->CurrentValue = $transaction->shipping_address_id->FormValue;
		$transaction->paydate->CurrentValue = $transaction->paydate->FormValue;
		$transaction->paydate->CurrentValue = ew_UnFormatDateTime($transaction->paydate->CurrentValue, 7);
		$transaction->modified_date->CurrentValue = $transaction->modified_date->FormValue;
		$transaction->modified_date->CurrentValue = ew_UnFormatDateTime($transaction->modified_date->CurrentValue, 11);
		$transaction->isInvalid->CurrentValue = $transaction->isInvalid->FormValue;
		$transaction->remarks->CurrentValue = $transaction->remarks->FormValue;
		$transaction->consignment_no->CurrentValue = $transaction->consignment_no->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $transaction;
		$sFilter = $transaction->KeyFilter();

		// Call Row Selecting event
		$transaction->Row_Selecting($sFilter);

		// Load SQL based on filter
		$transaction->CurrentFilter = $sFilter;
		$sSql = $transaction->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $transaction;
		if (!$rs || $rs->EOF) return;

		// Call Row Selected event
		$row =& $rs->fields;
		$transaction->Row_Selected($row);
		$transaction->id->setDbValue($rs->fields('id'));
		$transaction->order_no->setDbValue($rs->fields('order_no'));
		$transaction->user_id->setDbValue($rs->fields('user_id'));
		$transaction->amount->setDbValue($rs->fields('amount'));
		$transaction->status_payment->setDbValue($rs->fields('status_payment'));
		$transaction->status_transaction->setDbValue($rs->fields('status_transaction'));
		$transaction->total_item->setDbValue($rs->fields('total_item'));
		$transaction->total_weight->setDbValue($rs->fields('total_weight'));
		$transaction->postage_price->setDbValue($rs->fields('postage_price'));
		$transaction->items_price->setDbValue($rs->fields('items_price'));
		$transaction->type_price->setDbValue($rs->fields('type_price'));
		$transaction->shipping_address_id->setDbValue($rs->fields('shipping_address_id'));
		$transaction->appcode->setDbValue($rs->fields('appcode'));
		$transaction->tranid->setDbValue($rs->fields('tranid'));
		$transaction->domain->setDbValue($rs->fields('domain'));
		$transaction->status_nbepay->setDbValue($rs->fields('status_nbepay'));
		$transaction->currency->setDbValue($rs->fields('currency'));
		$transaction->paydate->setDbValue($rs->fields('paydate'));
		$transaction->channel->setDbValue($rs->fields('channel'));
		$transaction->serialkey->setDbValue($rs->fields('serialkey'));
		$transaction->vcode->setDbValue($rs->fields('vcode'));
		$transaction->modified_date->setDbValue($rs->fields('modified_date'));
		$transaction->created_date->setDbValue($rs->fields('created_date'));
		$transaction->isInvalid->setDbValue($rs->fields('isInvalid'));
		$transaction->remarks->setDbValue($rs->fields('remarks'));
		$transaction->consignment_no->setDbValue($rs->fields('consignment_no'));
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $transaction;

		// Initialize URLs
		// Call Row_Rendering event

		$transaction->Row_Rendering();

		// Common render codes for all row types
		// id
		// order_no
		// user_id
		// amount
		// status_payment
		// status_transaction
		// total_item
		// total_weight
		// postage_price
		// items_price
		// type_price
		// shipping_address_id
		// appcode
		// tranid
		// domain
		// status_nbepay
		// currency
		// paydate
		// channel
		// serialkey
		// vcode
		// modified_date
		// created_date
		// isInvalid
		// remarks
		// consignment_no

		if ($transaction->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$transaction->id->ViewValue = $transaction->id->CurrentValue;
			$transaction->id->ViewCustomAttributes = "";

			// order_no
			$transaction->order_no->ViewValue = $transaction->order_no->CurrentValue;
			$transaction->order_no->ViewCustomAttributes = "";

			// user_id
			$transaction->user_id->ViewValue = $transaction->user_id->CurrentValue;
			if (strval($transaction->user_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($transaction->user_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `username`, `name`, `no_ahli` FROM `user`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$transaction->user_id->ViewValue = $rswrk->fields('username');
					$transaction->user_id->ViewValue .= ew_ValueSeparator(0,1,$transaction->user_id) . $rswrk->fields('name');
					$transaction->user_id->ViewValue .= ew_ValueSeparator(0,2,$transaction->user_id) . $rswrk->fields('no_ahli');
					$rswrk->Close();
				} else {
					$transaction->user_id->ViewValue = $transaction->user_id->CurrentValue;
				}
			} else {
				$transaction->user_id->ViewValue = NULL;
			}
			$transaction->user_id->ViewCustomAttributes = "";

			// amount
			$transaction->amount->ViewValue = $transaction->amount->CurrentValue;
			$transaction->amount->ViewCustomAttributes = "";

			// status_payment
			$transaction->status_payment->ViewValue = $transaction->status_payment->CurrentValue;
			$transaction->status_payment->ViewCustomAttributes = "";

			// status_transaction
			if (strval($transaction->status_transaction->CurrentValue) <> "") {
				switch ($transaction->status_transaction->CurrentValue) {
					case "Waiting from admin action":
						$transaction->status_transaction->ViewValue = $transaction->status_transaction->FldTagCaption(1) <> "" ? $transaction->status_transaction->FldTagCaption(1) : $transaction->status_transaction->CurrentValue;
						break;
					case "Admin has confirmed products have delivered to a courier":
						$transaction->status_transaction->ViewValue = $transaction->status_transaction->FldTagCaption(2) <> "" ? $transaction->status_transaction->FldTagCaption(2) : $transaction->status_transaction->CurrentValue;
						break;
					case "Admin has confirmed products have received by customer":
						$transaction->status_transaction->ViewValue = $transaction->status_transaction->FldTagCaption(3) <> "" ? $transaction->status_transaction->FldTagCaption(3) : $transaction->status_transaction->CurrentValue;
						break;
					default:
						$transaction->status_transaction->ViewValue = $transaction->status_transaction->CurrentValue;
				}
			} else {
				$transaction->status_transaction->ViewValue = NULL;
			}
			$transaction->status_transaction->ViewCustomAttributes = "";

			// total_item
			$transaction->total_item->ViewValue = $transaction->total_item->CurrentValue;
			$transaction->total_item->ViewCustomAttributes = "";

			// total_weight
			$transaction->total_weight->ViewValue = $transaction->total_weight->CurrentValue;
			$transaction->total_weight->ViewCustomAttributes = "";

			// postage_price
			$transaction->postage_price->ViewValue = $transaction->postage_price->CurrentValue;
			$transaction->postage_price->ViewCustomAttributes = "";

			// items_price
			$transaction->items_price->ViewValue = $transaction->items_price->CurrentValue;
			$transaction->items_price->ViewCustomAttributes = "";

			// type_price
			if (strval($transaction->type_price->CurrentValue) <> "") {
				switch ($transaction->type_price->CurrentValue) {
					case "Harga Biasa":
						$transaction->type_price->ViewValue = $transaction->type_price->FldTagCaption(1) <> "" ? $transaction->type_price->FldTagCaption(1) : $transaction->type_price->CurrentValue;
						break;
					case "Harga Untuk Keahlian Ana Edar":
						$transaction->type_price->ViewValue = $transaction->type_price->FldTagCaption(2) <> "" ? $transaction->type_price->FldTagCaption(2) : $transaction->type_price->CurrentValue;
						break;
					default:
						$transaction->type_price->ViewValue = $transaction->type_price->CurrentValue;
				}
			} else {
				$transaction->type_price->ViewValue = NULL;
			}
			$transaction->type_price->ViewCustomAttributes = "";

			// shipping_address_id
			$transaction->shipping_address_id->ViewValue = $transaction->shipping_address_id->CurrentValue;
			if (strval($transaction->shipping_address_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($transaction->shipping_address_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `address`, `poskod`, `city` FROM `address`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$transaction->shipping_address_id->ViewValue = $rswrk->fields('address');
					$transaction->shipping_address_id->ViewValue .= ew_ValueSeparator(0,1,$transaction->shipping_address_id) . $rswrk->fields('poskod');
					$transaction->shipping_address_id->ViewValue .= ew_ValueSeparator(0,2,$transaction->shipping_address_id) . $rswrk->fields('city');
					$rswrk->Close();
				} else {
					$transaction->shipping_address_id->ViewValue = $transaction->shipping_address_id->CurrentValue;
				}
			} else {
				$transaction->shipping_address_id->ViewValue = NULL;
			}
			$transaction->shipping_address_id->ViewCustomAttributes = "";

			// paydate
			$transaction->paydate->ViewValue = $transaction->paydate->CurrentValue;
			$transaction->paydate->ViewValue = ew_FormatDateTime($transaction->paydate->ViewValue, 7);
			$transaction->paydate->ViewCustomAttributes = "";

			// modified_date
			$transaction->modified_date->ViewValue = $transaction->modified_date->CurrentValue;
			$transaction->modified_date->ViewValue = ew_FormatDateTime($transaction->modified_date->ViewValue, 11);
			$transaction->modified_date->ViewCustomAttributes = "";

			// created_date
			$transaction->created_date->ViewValue = $transaction->created_date->CurrentValue;
			$transaction->created_date->ViewValue = ew_FormatDateTime($transaction->created_date->ViewValue, 11);
			$transaction->created_date->ViewCustomAttributes = "";

			// isInvalid
			if (strval($transaction->isInvalid->CurrentValue) <> "") {
				switch ($transaction->isInvalid->CurrentValue) {
					case "0":
						$transaction->isInvalid->ViewValue = $transaction->isInvalid->FldTagCaption(1) <> "" ? $transaction->isInvalid->FldTagCaption(1) : $transaction->isInvalid->CurrentValue;
						break;
					case "1":
						$transaction->isInvalid->ViewValue = $transaction->isInvalid->FldTagCaption(2) <> "" ? $transaction->isInvalid->FldTagCaption(2) : $transaction->isInvalid->CurrentValue;
						break;
					default:
						$transaction->isInvalid->ViewValue = $transaction->isInvalid->CurrentValue;
				}
			} else {
				$transaction->isInvalid->ViewValue = NULL;
			}
			$transaction->isInvalid->ViewCustomAttributes = "";

			// remarks
			$transaction->remarks->ViewValue = $transaction->remarks->CurrentValue;
			$transaction->remarks->ViewCustomAttributes = "";

			// consignment_no
			$transaction->consignment_no->ViewValue = $transaction->consignment_no->CurrentValue;
			$transaction->consignment_no->ViewCustomAttributes = "";

			// order_no
			$transaction->order_no->LinkCustomAttributes = "";
			$transaction->order_no->HrefValue = "";
			$transaction->order_no->TooltipValue = "";

			// user_id
			$transaction->user_id->LinkCustomAttributes = "";
			$transaction->user_id->HrefValue = "";
			$transaction->user_id->TooltipValue = "";

			// amount
			$transaction->amount->LinkCustomAttributes = "";
			$transaction->amount->HrefValue = "";
			$transaction->amount->TooltipValue = "";

			// status_payment
			$transaction->status_payment->LinkCustomAttributes = "";
			$transaction->status_payment->HrefValue = "";
			$transaction->status_payment->TooltipValue = "";

			// status_transaction
			$transaction->status_transaction->LinkCustomAttributes = "";
			$transaction->status_transaction->HrefValue = "";
			$transaction->status_transaction->TooltipValue = "";

			// total_item
			$transaction->total_item->LinkCustomAttributes = "";
			$transaction->total_item->HrefValue = "";
			$transaction->total_item->TooltipValue = "";

			// total_weight
			$transaction->total_weight->LinkCustomAttributes = "";
			$transaction->total_weight->HrefValue = "";
			$transaction->total_weight->TooltipValue = "";

			// postage_price
			$transaction->postage_price->LinkCustomAttributes = "";
			$transaction->postage_price->HrefValue = "";
			$transaction->postage_price->TooltipValue = "";

			// items_price
			$transaction->items_price->LinkCustomAttributes = "";
			$transaction->items_price->HrefValue = "";
			$transaction->items_price->TooltipValue = "";

			// type_price
			$transaction->type_price->LinkCustomAttributes = "";
			$transaction->type_price->HrefValue = "";
			$transaction->type_price->TooltipValue = "";

			// shipping_address_id
			$transaction->shipping_address_id->LinkCustomAttributes = "";
			$transaction->shipping_address_id->HrefValue = "";
			$transaction->shipping_address_id->TooltipValue = "";

			// paydate
			$transaction->paydate->LinkCustomAttributes = "";
			$transaction->paydate->HrefValue = "";
			$transaction->paydate->TooltipValue = "";

			// modified_date
			$transaction->modified_date->LinkCustomAttributes = "";
			$transaction->modified_date->HrefValue = "";
			$transaction->modified_date->TooltipValue = "";

			// isInvalid
			$transaction->isInvalid->LinkCustomAttributes = "";
			$transaction->isInvalid->HrefValue = "";
			$transaction->isInvalid->TooltipValue = "";

			// remarks
			$transaction->remarks->LinkCustomAttributes = "";
			$transaction->remarks->HrefValue = "";
			$transaction->remarks->TooltipValue = "";

			// consignment_no
			$transaction->consignment_no->LinkCustomAttributes = "";
			$transaction->consignment_no->HrefValue = "";
			$transaction->consignment_no->TooltipValue = "";
		} elseif ($transaction->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// order_no
			$transaction->order_no->EditCustomAttributes = "";
			$transaction->order_no->EditValue = $transaction->order_no->CurrentValue;
			$transaction->order_no->ViewCustomAttributes = "";

			// user_id
			$transaction->user_id->EditCustomAttributes = "";
			$transaction->user_id->EditValue = $transaction->user_id->CurrentValue;
			if (strval($transaction->user_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($transaction->user_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `username`, `name`, `no_ahli` FROM `user`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$transaction->user_id->EditValue = $rswrk->fields('username');
					$transaction->user_id->EditValue .= ew_ValueSeparator(0,1,$transaction->user_id) . $rswrk->fields('name');
					$transaction->user_id->EditValue .= ew_ValueSeparator(0,2,$transaction->user_id) . $rswrk->fields('no_ahli');
					$rswrk->Close();
				} else {
					$transaction->user_id->EditValue = $transaction->user_id->CurrentValue;
				}
			} else {
				$transaction->user_id->EditValue = NULL;
			}
			$transaction->user_id->ViewCustomAttributes = "";

			// amount
			$transaction->amount->EditCustomAttributes = "";
			$transaction->amount->EditValue = $transaction->amount->CurrentValue;
			$transaction->amount->ViewCustomAttributes = "";

			// status_payment
			$transaction->status_payment->EditCustomAttributes = "";
			$transaction->status_payment->EditValue = $transaction->status_payment->CurrentValue;
			$transaction->status_payment->ViewCustomAttributes = "";

			// status_transaction
			$transaction->status_transaction->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("Waiting from admin action", $transaction->status_transaction->FldTagCaption(1) <> "" ? $transaction->status_transaction->FldTagCaption(1) : "Waiting from admin action");
			$arwrk[] = array("Admin has confirmed products have delivered to a courier", $transaction->status_transaction->FldTagCaption(2) <> "" ? $transaction->status_transaction->FldTagCaption(2) : "Admin has confirmed products have delivered to a courier");
			$arwrk[] = array("Admin has confirmed products have received by customer", $transaction->status_transaction->FldTagCaption(3) <> "" ? $transaction->status_transaction->FldTagCaption(3) : "Admin has confirmed products have received by customer");
			$transaction->status_transaction->EditValue = $arwrk;

			// total_item
			$transaction->total_item->EditCustomAttributes = "";
			$transaction->total_item->EditValue = $transaction->total_item->CurrentValue;
			$transaction->total_item->ViewCustomAttributes = "";

			// total_weight
			$transaction->total_weight->EditCustomAttributes = "";
			$transaction->total_weight->EditValue = $transaction->total_weight->CurrentValue;
			$transaction->total_weight->ViewCustomAttributes = "";

			// postage_price
			$transaction->postage_price->EditCustomAttributes = "";
			$transaction->postage_price->EditValue = $transaction->postage_price->CurrentValue;
			$transaction->postage_price->ViewCustomAttributes = "";

			// items_price
			$transaction->items_price->EditCustomAttributes = "";
			$transaction->items_price->EditValue = $transaction->items_price->CurrentValue;
			$transaction->items_price->ViewCustomAttributes = "";

			// type_price
			$transaction->type_price->EditCustomAttributes = "";
			if (strval($transaction->type_price->CurrentValue) <> "") {
				switch ($transaction->type_price->CurrentValue) {
					case "Harga Biasa":
						$transaction->type_price->EditValue = $transaction->type_price->FldTagCaption(1) <> "" ? $transaction->type_price->FldTagCaption(1) : $transaction->type_price->CurrentValue;
						break;
					case "Harga Untuk Keahlian Ana Edar":
						$transaction->type_price->EditValue = $transaction->type_price->FldTagCaption(2) <> "" ? $transaction->type_price->FldTagCaption(2) : $transaction->type_price->CurrentValue;
						break;
					default:
						$transaction->type_price->EditValue = $transaction->type_price->CurrentValue;
				}
			} else {
				$transaction->type_price->EditValue = NULL;
			}
			$transaction->type_price->ViewCustomAttributes = "";

			// shipping_address_id
			$transaction->shipping_address_id->EditCustomAttributes = "";
			$transaction->shipping_address_id->EditValue = $transaction->shipping_address_id->CurrentValue;
			if (strval($transaction->shipping_address_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($transaction->shipping_address_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `address`, `poskod`, `city` FROM `address`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$transaction->shipping_address_id->EditValue = $rswrk->fields('address');
					$transaction->shipping_address_id->EditValue .= ew_ValueSeparator(0,1,$transaction->shipping_address_id) . $rswrk->fields('poskod');
					$transaction->shipping_address_id->EditValue .= ew_ValueSeparator(0,2,$transaction->shipping_address_id) . $rswrk->fields('city');
					$rswrk->Close();
				} else {
					$transaction->shipping_address_id->EditValue = $transaction->shipping_address_id->CurrentValue;
				}
			} else {
				$transaction->shipping_address_id->EditValue = NULL;
			}
			$transaction->shipping_address_id->ViewCustomAttributes = "";

			// paydate
			$transaction->paydate->EditCustomAttributes = "";
			$transaction->paydate->EditValue = $transaction->paydate->CurrentValue;
			$transaction->paydate->EditValue = ew_FormatDateTime($transaction->paydate->EditValue, 7);
			$transaction->paydate->ViewCustomAttributes = "";

			// modified_date
			// isInvalid

			$transaction->isInvalid->EditCustomAttributes = "";
			if (strval($transaction->isInvalid->CurrentValue) <> "") {
				switch ($transaction->isInvalid->CurrentValue) {
					case "0":
						$transaction->isInvalid->EditValue = $transaction->isInvalid->FldTagCaption(1) <> "" ? $transaction->isInvalid->FldTagCaption(1) : $transaction->isInvalid->CurrentValue;
						break;
					case "1":
						$transaction->isInvalid->EditValue = $transaction->isInvalid->FldTagCaption(2) <> "" ? $transaction->isInvalid->FldTagCaption(2) : $transaction->isInvalid->CurrentValue;
						break;
					default:
						$transaction->isInvalid->EditValue = $transaction->isInvalid->CurrentValue;
				}
			} else {
				$transaction->isInvalid->EditValue = NULL;
			}
			$transaction->isInvalid->ViewCustomAttributes = "";

			// remarks
			$transaction->remarks->EditCustomAttributes = "";
			$transaction->remarks->EditValue = ew_HtmlEncode($transaction->remarks->CurrentValue);

			// consignment_no
			$transaction->consignment_no->EditCustomAttributes = "";
			$transaction->consignment_no->EditValue = ew_HtmlEncode($transaction->consignment_no->CurrentValue);

			// Edit refer script
			// order_no

			$transaction->order_no->HrefValue = "";

			// user_id
			$transaction->user_id->HrefValue = "";

			// amount
			$transaction->amount->HrefValue = "";

			// status_payment
			$transaction->status_payment->HrefValue = "";

			// status_transaction
			$transaction->status_transaction->HrefValue = "";

			// total_item
			$transaction->total_item->HrefValue = "";

			// total_weight
			$transaction->total_weight->HrefValue = "";

			// postage_price
			$transaction->postage_price->HrefValue = "";

			// items_price
			$transaction->items_price->HrefValue = "";

			// type_price
			$transaction->type_price->HrefValue = "";

			// shipping_address_id
			$transaction->shipping_address_id->HrefValue = "";

			// paydate
			$transaction->paydate->HrefValue = "";

			// modified_date
			$transaction->modified_date->HrefValue = "";

			// isInvalid
			$transaction->isInvalid->HrefValue = "";

			// remarks
			$transaction->remarks->HrefValue = "";

			// consignment_no
			$transaction->consignment_no->HrefValue = "";
		}
		if ($transaction->RowType == EW_ROWTYPE_ADD ||
			$transaction->RowType == EW_ROWTYPE_EDIT ||
			$transaction->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
			$transaction->SetupFieldTitles();
		}

		// Call Row Rendered event
		if ($transaction->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$transaction->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError, $transaction;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if ($transaction->status_transaction->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $transaction->status_transaction->FldCaption());
		}

		// Validate detail grid
		if ($transaction->getCurrentDetailTable() == "purchaseproduct" && $GLOBALS["purchaseproduct"]->DetailEdit) {
			$purchaseproduct_grid = new cpurchaseproduct_grid(); // get detail page object
			$purchaseproduct_grid->ValidateGridForm();
			$purchaseproduct_grid = NULL;
		}
		if ($transaction->getCurrentDetailTable() == "transaction_log" && $GLOBALS["transaction_log"]->DetailEdit) {
			$transaction_log_grid = new ctransaction_log_grid(); // get detail page object
			$transaction_log_grid->ValidateGridForm();
			$transaction_log_grid = NULL;
		}
		if ($transaction->getCurrentDetailTable() == "address" && $GLOBALS["address"]->DetailEdit) {
			$address_grid = new caddress_grid(); // get detail page object
			$address_grid->ValidateGridForm();
			$address_grid = NULL;
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			ew_AddMessage($gsFormError, $sFormCustomError);
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language, $transaction;
		$sFilter = $transaction->KeyFilter();
		$transaction->CurrentFilter = $sFilter;
		$sSql = $transaction->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$EditRow = FALSE; // Update Failed
		} else {

			// Begin transaction
			if ($transaction->getCurrentDetailTable() <> "")
				$conn->BeginTrans();

			// Save old values
			$rsold =& $rs->fields;
			$rsnew = array();

			// status_transaction
			$transaction->status_transaction->SetDbValueDef($rsnew, $transaction->status_transaction->CurrentValue, NULL, $transaction->status_transaction->ReadOnly);

			// modified_date
			$transaction->modified_date->SetDbValueDef($rsnew, ew_CurrentDateTime(), NULL);
			$rsnew['modified_date'] =& $transaction->modified_date->DbValue;

			// remarks
			$transaction->remarks->SetDbValueDef($rsnew, $transaction->remarks->CurrentValue, NULL, $transaction->remarks->ReadOnly);

			// consignment_no
			$transaction->consignment_no->SetDbValueDef($rsnew, $transaction->consignment_no->CurrentValue, NULL, $transaction->consignment_no->ReadOnly);

			// Call Row Updating event
			$bUpdateRow = $transaction->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
				$conn->raiseErrorFn = 'ew_ErrorFn';
				if (count($rsnew) > 0)
					$EditRow = $conn->Execute($transaction->UpdateSQL($rsnew));
				else
					$EditRow = TRUE; // No field to update
				$conn->raiseErrorFn = '';

				// Update detail records
				if ($EditRow) {
					if ($transaction->getCurrentDetailTable() == "purchaseproduct" && $GLOBALS["purchaseproduct"]->DetailEdit) {
						$purchaseproduct_grid = new cpurchaseproduct_grid(); // get detail page object
						$EditRow = $purchaseproduct_grid->GridUpdate();
						$purchaseproduct_grid = NULL;
					}
					if ($transaction->getCurrentDetailTable() == "transaction_log" && $GLOBALS["transaction_log"]->DetailEdit) {
						$transaction_log_grid = new ctransaction_log_grid(); // get detail page object
						$EditRow = $transaction_log_grid->GridUpdate();
						$transaction_log_grid = NULL;
					}
					if ($transaction->getCurrentDetailTable() == "address" && $GLOBALS["address"]->DetailEdit) {
						$address_grid = new caddress_grid(); // get detail page object
						$EditRow = $address_grid->GridUpdate();
						$address_grid = NULL;
					}
				}

				// Commit/Rollback transaction
				if ($transaction->getCurrentDetailTable() <> "") {
					if ($EditRow) {
						$conn->CommitTrans(); // Commit transaction
					} else {
						$conn->RollbackTrans(); // Rollback transaction
					}
				}
			} else {
				if ($transaction->CancelMessage <> "") {
					$this->setFailureMessage($transaction->CancelMessage);
					$transaction->CancelMessage = "";
				} else {
					$this->setFailureMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$transaction->Row_Updated($rsold, $rsnew);
		$rs->Close();
		return $EditRow;
	}

	// Set up master/detail based on QueryString
	function SetUpMasterParms() {
		global $transaction;
		$bValidMaster = FALSE;

		// Get the keys for master table
		if (@$_GET[EW_TABLE_SHOW_MASTER] <> "") {
			$sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER];
			if ($sMasterTblVar == "") {
				$bValidMaster = TRUE;
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
			}
			if ($sMasterTblVar == "user") {
				$bValidMaster = TRUE;
				if (@$_GET["id"] <> "") {
					$GLOBALS["user"]->id->setQueryStringValue($_GET["id"]);
					$transaction->user_id->setQueryStringValue($GLOBALS["user"]->id->QueryStringValue);
					$transaction->user_id->setSessionValue($transaction->user_id->QueryStringValue);
					if (!is_numeric($GLOBALS["user"]->id->QueryStringValue)) $bValidMaster = FALSE;
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

			// Save current master table
			$transaction->setCurrentMasterTable($sMasterTblVar);

			// Reset start record counter (new master key)
			$this->StartRec = 1;
			$transaction->setStartRecordNumber($this->StartRec);

			// Clear previous master key from Session
			if ($sMasterTblVar <> "user") {
				if ($transaction->user_id->QueryStringValue == "") $transaction->user_id->setSessionValue("");
			}
		}
		$this->DbMasterFilter = $transaction->getMasterFilter(); //  Get master filter
		$this->DbDetailFilter = $transaction->getDetailFilter(); // Get detail filter
	}

	// Set up detail parms based on QueryString
	function SetUpDetailParms() {
		global $transaction;
		$bValidDetail = FALSE;

		// Get the keys for master table
		if (isset($_GET[EW_TABLE_SHOW_DETAIL])) {
			$sDetailTblVar = $_GET[EW_TABLE_SHOW_DETAIL];
			$transaction->setCurrentDetailTable($sDetailTblVar);
		} else {
			$sDetailTblVar = $transaction->getCurrentDetailTable();
		}
		if ($sDetailTblVar <> "") {
			if ($sDetailTblVar == "purchaseproduct") {
				if (!isset($GLOBALS["purchaseproduct"]))
					$GLOBALS["purchaseproduct"] = new cpurchaseproduct;
				if ($GLOBALS["purchaseproduct"]->DetailEdit) {
					$GLOBALS["purchaseproduct"]->CurrentMode = "edit";
					$GLOBALS["purchaseproduct"]->CurrentAction = "gridedit";

					// Save current master table to detail table
					$GLOBALS["purchaseproduct"]->setCurrentMasterTable($transaction->TableVar);
					$GLOBALS["purchaseproduct"]->setStartRecordNumber(1);
					$GLOBALS["purchaseproduct"]->transaction_id->FldIsDetailKey = TRUE;
					$GLOBALS["purchaseproduct"]->transaction_id->CurrentValue = $transaction->id->CurrentValue;
					$GLOBALS["purchaseproduct"]->transaction_id->setSessionValue($GLOBALS["purchaseproduct"]->transaction_id->CurrentValue);
				}
			}
			if ($sDetailTblVar == "transaction_log") {
				if (!isset($GLOBALS["transaction_log"]))
					$GLOBALS["transaction_log"] = new ctransaction_log;
				if ($GLOBALS["transaction_log"]->DetailEdit) {
					$GLOBALS["transaction_log"]->CurrentMode = "edit";
					$GLOBALS["transaction_log"]->CurrentAction = "gridedit";

					// Save current master table to detail table
					$GLOBALS["transaction_log"]->setCurrentMasterTable($transaction->TableVar);
					$GLOBALS["transaction_log"]->setStartRecordNumber(1);
					$GLOBALS["transaction_log"]->transaction_id->FldIsDetailKey = TRUE;
					$GLOBALS["transaction_log"]->transaction_id->CurrentValue = $transaction->id->CurrentValue;
					$GLOBALS["transaction_log"]->transaction_id->setSessionValue($GLOBALS["transaction_log"]->transaction_id->CurrentValue);
				}
			}
			if ($sDetailTblVar == "address") {
				if (!isset($GLOBALS["address"]))
					$GLOBALS["address"] = new caddress;
				if ($GLOBALS["address"]->DetailEdit) {
					$GLOBALS["address"]->CurrentMode = "edit";
					$GLOBALS["address"]->CurrentAction = "gridedit";

					// Save current master table to detail table
					$GLOBALS["address"]->setCurrentMasterTable($transaction->TableVar);
					$GLOBALS["address"]->setStartRecordNumber(1);
					$GLOBALS["address"]->id->FldIsDetailKey = TRUE;
					$GLOBALS["address"]->id->CurrentValue = $transaction->shipping_address_id->CurrentValue;
					$GLOBALS["address"]->id->setSessionValue($GLOBALS["address"]->id->CurrentValue);
				}
			}
		}
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'
	function Message_Showing(&$msg, $type) {

		// Example:
		//if ($type == 'success') $msg = "your success message";

	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
